package cn.ffcs.uec.staff.model;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.organization.model.UecOrgOrgs;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.model.UomEntity;
import cn.ffcs.uom.common.util.StrUtil;

/**
 * 履历记录
 * 
 * @Title:
 * @Description:
 * @Copyright: FFCS（C） 2017
 * @Company: FFCS
 * @author Wang Yiren
 * @Version 0.0.1 date:2017年12月14日
 * @since JDK1.6
 */
public class UecWork extends UomEntity implements Serializable {

    private static final long serialVersionUID = 2494986330492021633L;

    /**
     * 履历记录标识
     * 
     * @return
     */
    public Long getWorkId() {
        return super.getId();
    }

    public void setWorkId(Long workId) {
        super.setId(workId);
    }

    /**
     * 人员标识
     */
    @Getter
    @Setter
    private Long staffId;

    /**
     * 员工类型 1：合同制、派遣制 2：外包自有、其他
     */
	@Getter
	@Setter
	private String nmStaffType;

    /**
     * 账期
     */
    @Getter
    @Setter
    private Long monthId;

    /**
     * 开始时间
     */
    @Getter
    @Setter
    private String begindate;

    /**
     * 证明人
     */
    @Getter
    @Setter
    private String certifier;

    /**
     * 证明人电话
     */
    @Getter
    @Setter
    private String certiphone;

    /**
     * 创建时间
     */
    @Getter
    @Setter
    private String creationtime;

    /**
     * 离职原因
     */
    @Getter
    @Setter
    private String dimissionReason;

    /**
     * 删除标示
     */
    @Getter
    @Setter
    private Long dr;

    /**
     * 结束日期
     */
    @Getter
    @Setter
    private String enddate;

    /**
     * 岗位层级
     */
    @Getter
    @Setter
    private String glbdef1;

    /**
     * 岗位等级
     */
    @Getter
    @Setter
    private String glbdef2;

    /**
     * 最近记录标志
     */
    @Getter
    @Setter
    private String lastflag;

    /**
     * 修改时间
     */
    @Getter
    @Setter
    private String modifiedtime;

    /**
     * 修改人
     */
    @Getter
    @Setter
    private String modifier;

    /**
     * 所属组织
     */
    @Getter
    @Setter
    private String pkOrg;

    /**
     * 人员基本信息
     */
    @Getter
    @Setter
    private String pkPsndoc;

    /**
     * 主键
     */
    @Getter
    @Setter
    private String pkPsndocSub;

    /**
     * 任职主键
     */
    @Getter
    @Setter
    private String pkPsnjob;

    /**
     * 组织关系主键
     */
    @Getter
    @Setter
    private String pkPsnorg;

    /**
     * 记录序号
     */
    @Getter
    @Setter
    private Long recordnum;

    /**
     * 时间戳
     */
    @Getter
    @Setter
    private String ts;

    /**
     * 工作单位
     */
    @Getter
    @Setter
    private String workcorp;

    /**
     * 部门
     */
    @Getter
    @Setter
    private String workdept;

    /**
     * 职务
     */
    @Getter
    @Setter
    private String workjob;

    /**
     * 岗位
     */
    @Getter
    @Setter
    private String workpost;

    /**
     * 岗位层级_zy
     */
    @Getter
    @Setter
    private String glbdef3;

    /**
     * 岗位等级_zy
     */
    @Getter
    @Setter
    private String glbdef4;

    /**
     * 所在部门
     */
    @Getter
    @Setter
    private String glbdef5;

    /**
     * 创建对象实例
     */
    public static UecWork newInstance() {
        return new UecWork();
    }

    /**
     * 岗位层级--glbdef1
     */
    public String getGlbdef1Name() {
        if (this.getGlbdef1() != null) {
            String sql = " SELECT * FROM UEC_BD_DEFDOC WHERE PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef1());
            List<UecBdDefdoc> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 岗位层级_zy--glbdef3
     */
    public String getGlbdef3Name() {
        if (this.getGlbdef3() != null) {
            String sql = " SELECT * FROM UEC_BD_DEFDOC WHERE PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef3());
            List<UecBdDefdoc> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 岗位等级 名称
     * 
     * @return
     */
    public String getGlbdef2Name() {
        if (this.getGlbdef2() != null) {
            String sql = " SELECT * FROM UEC_BD_DEFDOC WHERE PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef2());
            List<UecBdDefdoc> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 岗位等级_zy--glbdef4
     */
    public String getGlbdef4Name() {
        if (this.getGlbdef4() != null) {
            String sql = " SELECT * FROM UEC_BD_DEFDOC WHERE PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef4());
            List<UecBdDefdoc> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 所属组织--pkOrg
     */
    public String getPkOrgName() {
        if (this.getPkOrg() != null) {
            String sql = " SELECT * FROM UEC_ORG_ORGS T WHERE T.pk_org = ? and t.status_cd = '1000' ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getPkOrg());
            List<UecOrgOrgs> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecOrgOrgs.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }
    
    
    //在何单位何部门任何职（岗位）
    public String getColletionSelect() {
    	String tepm="";
    	if(!StrUtil.isNullOrEmpty(this.workcorp)) {
    		tepm=this.workcorp;
    	}
    	if(!StrUtil.isNullOrEmpty(this.workdept)) {
    		tepm = tepm +" "+this.workdept;
    	}
    	if(!StrUtil.isNullOrEmpty(this.workpost)) {
    		tepm = tepm +" "+this.workpost;
    	}
    	return tepm;
    }
    
    public String dataTraslate(String data) throws ParseException {
    	SimpleDateFormat df=new SimpleDateFormat("yyyy-mm");
    	Date parse = df.parse(data);
    	String newDate = df.format(parse);
    	return newDate;
    }
    public String getDataCollection() throws ParseException {
    	String aa="";
    	String bb="";
    	String cc="";
    	//aa=dataTraslate(this.getBegindate());
    	if(!StrUtil.isNullOrEmpty(this.begindate)) {
    		aa=dataTraslate(this.begindate);
    	}
    	if(!StrUtil.isNullOrEmpty(this.enddate)) {
    		bb=dataTraslate(this.enddate);
    		bb=bb.replace('-', '.');
    	}else {
    		if("Y".equals(this.lastflag)) {
    			bb="至今";
    		}
    	}
			cc=aa.replace('-', '.') +" ~ " +bb;
    	return cc;
    }
}
